define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'form_merchant/index' + location.search,
                    add_url: 'form_merchant/add',
                    edit_url: 'form_merchant/edit',
                    del_url: 'form_merchant/del',
                    multi_url: 'form_merchant/multi',
                    table: 'form_merchant',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        // {field: 'openid', title: __('Openid')},
                        {field: 'nickname', title: __('Nickname')},
                        {field: 'tel', title: __('Tel')},
                        {field: 'a_3', title: __('A_3'),formatter: Table.api.formatter.qingkuang},
                        {field: 'a_3_1', title: __('A_3_1')},
                        {field: 'a_4', title: __('A_4'),formatter: Table.api.formatter.jiechu},
                        {field: 'a_4_1', title: __('A_4_1')},
                        {field: 'a_5', title: __('A_5'),formatter: Table.api.formatter.yixue},
                        {field: 'a_5_1', title: __('A_5_1')},
                        {field: 'a_5_2', title: __('A_5_2'),formatter: Table.api.formatter.yesorno},
                        {field: 'a_6', title: __('A_6'),formatter: Table.api.formatter.shengti},
                        {field: 'a_6_1', title: __('A_6_1')},
                        {field: 'a_7', title: __('A_7'),formatter: Table.api.formatter.jiating},
                        {field: 'a_7_1', title: __('A_7_1')},
                        {field: 'create_time', title: __('Create_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'address', title: '微信地址',operate:false},
                        //{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});